<?php
class Myh_File_Upload
{
	public function Upload($fileName, $uploadDir, $options = null, $filePrefix = 'file_')
	{
		$upload = new Zend_File_Transfer_Adapter_Http();
		//Upload no rename
		if($options==null){
			$upload -> setDestination($uploadDir, $fileName);
			$upload -> receive($fileName);
			$info   = $upload -> getFileInfo($fileName); 
			$newFileName = $info[$fileName]['name'];
			
		}else{
			//Upload with rename
			if($options['task']=='rename'){
				$info = $upload->getFileName($fileName);
				preg_match('#\.([^\.]+)$#', $info, $matches);
				$fileExten = $matches[1];
				$newFileName = 	$filePrefix . time() . '.' .$fileExten;
				$options = array('target'=>$uploadDir . '/' .$newFileName, 'overwrite'=>true);
				$upload -> addFilter('Rename', $options, $fileName);
				$upload -> receive($fileName);
			}
		}
		return $newFileName;
	}
	public function RemoveFile($fileName)
	{
		@unlink($fileName);
	}
}